class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if n == 1:
            return True
        tmp = 1
        while tmp < n:
            tmp = tmp * 3
        return tmp == n


if __name__ == '__main__':
    so = Solution()
    n = 27
    r = so.isPowerOfThree(n)
    print(r)
